package com.gdwProject.smallchangeOOP;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;


public class SmallChangeOOP {
    String detail = "";
    //int input = 0;
    double balance = 0;
    double money = 0;
    String note = "";
    char exit = ' ';
    Date date = null;
    Boolean loop=true;
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat
            ("yyyy-MM-dd HH:mm");
    public void menu(){
        System.out.println("-------------零钱通菜单(OOP)--------------");
        System.out.println("\t\t\t1 零钱通明细");
        System.out.println("\t\t\t2 收益入账");
        System.out.println("\t\t\t3 消费");
        System.out.println("\t\t\t4 退     出");
    }

    public void detail(){
        System.out.print("---------------零钱通明细----------------");
        System.out.println(detail);
    }

    public void income(){
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入收益金额：");
        money = scanner.nextDouble();
        while (money <= 0) {
            System.out.print("收益金额必须>0，请重新输入:");
            money = scanner.nextDouble();
        }
        balance += money;
        date = new Date();
        simpleDateFormat.format(date);
        detail += "\n收益入账\t+" + money + "\t"
                + simpleDateFormat.format(date) + "\t余额:" + balance;
    }

    public void pay(){
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入消费去向：");
        note = scanner.next();
        System.out.print("请输入消费金额：");
        money = scanner.nextDouble();
        while (money > balance) {
            System.out.print("余额不足，请重新输入消费金额:");
            money = scanner.nextDouble();
        }
        balance -= money;
        date = new Date();
        detail += "\n" + note + "\t-" + money + "\t"
                + simpleDateFormat.format(date) + "\t余额:" + balance;
    }

    public void exit(){
        Scanner scanner = new Scanner(System.in);
        System.out.print("确定要退出程序吗？(y/n)->");
        exit = scanner.next().charAt(0);
        while (exit != 'y' && exit != 'n') {
            System.out.print("请输入正确的格式(y/n)->:");
            exit = scanner.next().charAt(0);
        }
        if (exit == 'n') {
            return;
        }
        loop = false;
        System.out.println("退出程序...");
        return;
    }
}
